from django.core.management.base import BaseCommand
from web.models import  LoanOrder
import datetime
class Command(BaseCommand):
    def handle(self, *args, **kwargs):
        # 执行更新数据库值的操作
        try:
            my_objects = LoanOrder.objects.all()
            # 判断是否有订单过期了
            today = datetime.date.today()
            for i in my_objects:
                if i.repayment_time.strftime("%Y-%m-%d") < str(today):
                    if i.status == 3:
                        i.status = 5
                        i.save()
            self.stdout.write(self.style.SUCCESS("数据库更新成功"))
        except Exception as e:
            self.stderr.write(self.style.ERROR(f"An error occurred: {e}"))



